def __init__(self,argument,...,*argument): Statements ----------
class Student: def __init__(self,rn,nm,br,*mks): self.rollno=rn self.name=nm self.branch=br self.marks=mks def showData(self): print("RollNo is",self.rollno) print("Name is",self.name) print("Branch is",self.branch) def total(self): t=0 for mk in self.marks: t=t+mk return t def percentage(self): c=0 for mk in self.marks: c=c+1 p=self.total()/c return p def result(self): for mk in self.marks: if mk<40: return "Fail" else: return "Pass" a=Student(4117,"Amit Jain","CSE-3",56,27,56,67,78,67) a.showData() print("Total is",a.total()) print("Percentage is",a.percentage()) print("Result is",a.result())
RollNo is 4117 Name is Amit Jain Branch is CSE-3 Total is 342 Percentage is 57.40 Result is Fail
def __init__(self,argument,...,**kwargument): Statements ----------
class Student: def __init__(self,rn,nm,**kwargs): self.rollno=rn self.name=nm self.marks=kwargs def showData(self): print("RollNo :",self.rollno) print("Name :",self.name) for sub,mk in self.marks.items(): print(sub,":",mk) def result(self): s=0 for sb,mk in self.marks.items(): s=s+mk print("Total is ",s) a=Student(4117,"Amit Jain",PM=67,OS=87,SS=75,DS=45) a.showData() a.result()
Rollno: 4117 Name: Amit Jain PM : 67 OS : 87 SS : 75 DS : 45 Total is 274